<template>
  <div class="app-container">
    <!-- 工具栏 -->
    <!-- <tl-list-toolbar ref="toolbar" :isDisplayAdd="editable" :isDisplayExport="false" :isDisplayDeleteBatch="editable" @add="openAddDialog('editForm')" @exportExcel="doExportExcel" @deleteBatch="doDeleteBatch" @refresh="doRefresh" @columnCustomize="doColumnCustomize" @displaySearch="doDisplaySearch" :disableDeleteBatch="selectedRowKeys.length <= 0">
      <template slot="left-btn">
        <el-button class="filter-item" type="primary" icon="el-icon-plus" @click="openAddDialog('editTemplateForm')" v-show="editable">按模板新增</el-button>
        <el-button class="filter-item" type="primary" icon="el-icon-plus" :projectinfo="projectinfo" @click="openAddDialog('editProjectForm')" v-show="editable">按项目新增</el-button>
      </template>
    </tl-list-toolbar> -->
    <div style="margin-top:6px">
      <!-- 列表选择 -->
      <div class="table-alert-div" ref="selector">
        <el-alert type="success" :closable="false" class="tl-table-alert-info" effect="light">
          <template slot="title">
            已选择&nbsp;<a class="tl-table-alert-info-a1">{{ selectedRowKeys.length }}</a
            >项&nbsp;&nbsp;
            <a class="tl-table-alert-info-a2" @click="doClearSelected">全部清空</a>
          </template>
        </el-alert>
      </div>
      <!--表格渲染-->
      <el-table class="tl-table" ref="mainTable" :height="tableHeight" :row-style="tableRowStyle" resizable-key="tableHeight" :resizable-refs="tableResizeRefs" v-loading="loading" :data="datas" @selection-change="doSelectChange" @sort-change="doSortChange" @row-dblclick="doRowDbClick" @row-click="doRowClick" row-key="id" border fit :row-class-name="doChangeRowClassName">
        <el-table-column type="index" label="序号" width="55px" align="center"></el-table-column>
        <el-table-column prop="milepostname" label="里程碑名称" width="300px" sortable="custom" sort-by="milepostname" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="deliverable" label="交付成果" sortable="custom" sort-by="deliverable" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispmilepoststate" label="里程碑状态" width="120px" sortable="custom" sort-by="milepoststate" align="center" header-align="center" :show-overflow-tooltip="true">
          <template v-slot="scope">
            <el-tag :type="changeStateType(scope.row.milepoststate)">
              {{ scope.row.dispmilepoststate }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="responsible" label="责任人" width="120px" sortable="custom" sort-by="responsible" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="planfinishtime" label="计划达成日期" width="160px" sortable="custom" sort-by="planfinishtime" align="center" header-align="center" :show-overflow-tooltip="true" :formatter="dateFormat"></el-table-column>
      </el-table>
      <!-- 列表分页 -->
      <el-row class="pagebar" ref="pager">
        <el-pagination @size-change="doChangeSize" @current-change="doChangeIndex" :current-page="pageInfo.currentPage" :page-sizes="pageInfo.pageSizes" :total="pageInfo.totalCount" layout="total, sizes, prev, pager, next, jumper" background class="tl-table-pagination"> </el-pagination>
      </el-row>
      <tl-edit ref="editForm" @refresh="doRefresh" :parentId="parentId" :projectinfo="projectinfo"></tl-edit>
      <tl-edit-template ref="editTemplateForm" @refresh="doRefresh" :parentId="parentId" :projectinfo="projectinfo"></tl-edit-template>
      <tl-edit-project ref="editProjectForm" @refresh="doRefresh" :parentId="parentId" :projectinfo="projectinfo"></tl-edit-project>
    </div>
  </div>
</template>

<script>
/** mixins */
import { mixin_list } from '@tapui/mixins/mixin_list'
/** 子组件 */
import tlEdit from './edit'
import tlEditTemplate from './editTemplate'
import { checkPermission } from '@tapui/utils/permission'
import tlEditProject from './editProject'
/** 工具类 */
import { getAction, putAction, postAction, deleteAction } from '@tapui/utils/http'
export default {
  name: 'sdProjectMilepost',
  mixins: [mixin_list],
  components: { tlEdit, tlEditTemplate, tlEditProject },
  data() {
    return {
      description: '项目策划-里程碑-列表查询',
      urlPrefix: '/sd/projectMilepost/',
      url: {
        // queryCodeList: '/sd/projectMilepost/dataCodeList'
        list: '/sd/projectMilepost/list',
        load: '/sd/projectMilepost/load'
      },
      reduceHeight: 282,
      rowDbClickActionType: 'view',
      // 排序参数
      sorterInfo: {
        sidx: 'planfinishtime',
        sord: 'asc'
      },
      datas: [],
      operatecode: '',
      datamsg: {}
    }
  },
  props: {
    parentId: {
      type: [Number, String],
      default: ''
    },
    editable: {
      type: Boolean,
      default: true
    },
    projectinfo: {}
  },
  methods: {
    /** 改变审核状态标签颜色 */
    changeStateType(state) {
      return state === 0 ? 'info' : 'success'
    },
    doRowDbClick(row, column, event) {
      if (this.rowDbClickActionType === 'edit') {
        // 判断是否有权限
        if (this.editPermission.length > 0) {
          if (checkPermission(this.editPermission)) {
            this.openEditDialog('editForm', row[this.$refs.mainTable.rowKey])
          } else {
            this.openViewDialog('editForm', row[this.$refs.mainTable.rowKey])
          }
        } else {
          this.openEditDialog('editForm', row[this.$refs.mainTable.rowKey])
        }
      } else if (this.rowDbClickActionType === 'view') {
        this.openViewDialog('editForm', row[this.$refs.mainTable.rowKey])
      }
    },
    initPage() {
      if (this.editable) {
        this.rowDbClickActionType = 'edit'
      } else {
        this.rowDbClickActionType = 'view'
      }
    },
    beforeLoadData() {
      this.queryParam.qry_projectcode = this.projectinfo.projectcode
      this.queryParam.qry_enabled = 1
      return true
    },
    // 行颜色
    tableRowStyle(row, index) {
      // 如果计划完成时间为空，则行颜色为空
      if (row.row.planfinishtime === undefined || row.row.planfinishtime === null || row.row.planfinishtime === '') {
        return {}
      } else {
        let currentTime = new Date()
        // 替换字符 变为标准格式
        let customTime = row.row.planfinishtime.replace('-', '/')
        customTime = new Date(Date.parse(customTime))
        // 如果当前时间 > 计划达成日期
        if (currentTime > customTime && !row.row.actualfinishtime) {
          return { 'background-color': '#FF8C2E', color: '#FFFFFF' }
        }
      }
    }
  }
}
</script>

<style scoped>
.app-container {
  margin: 0;
}
</style>
